import { Ref } from 'vue'
import { ElButton } from 'element-plus'
import { TableColumn } from '@/components/Table'
import { useI18n } from '@/hooks/web/useI18n'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()

import { hasPermission } from '@/utils'
export const useOrderReturnTableColumns = (
  handleJump: Function,
  examineHandle: Function,
  handleCancel: Function,
  useEnumeratePicker: Function,
  returnorderTypeList: Ref<any[]>,
  orderTypeList: Ref<any[]>,
  operatorList: Ref<any[]>,
  statusList: Ref<any[]>
): TableColumn[] => {
  const { t } = useI18n()

  return [
    {
      field: 'selection',
      type: 'selection',
      width: 55,
      align: 'center',
      headerAlign: 'center'
    },
    {
      field: 'id',
      label: t('expandCustomer.serialNumber'),
      minWidth: 70,
      align: 'center',
      headerAlign: 'center'
    },
    {
      field: 'returnorder_no',
      label: t('orderReturn.returnorder_no'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'order_no',
      label: t('order.orderCode'),
      minWidth: 180,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'order_id',
      label: t('order.order_id'),
      minWidth: 120,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'returnorder_type',
      label: t('orderReturn.returnorder_type'),
      minWidth: 250,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true,
      slots: {
        default: ({ row }) => useEnumeratePicker(returnorderTypeList.value, row.returnorder_type)
      }
    },
    {
      field: 'customer_name',
      label: t('orderReturn.customer_name'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    // {
    //   field: 'order_no',
    //   label: t('orderReturn.order_no'),
    //   minWidth: 200,
    //   align: 'center',
    //   headerAlign: 'center',
    //   showOverflowTooltip: true
    // },
    {
      field: 'order_type',
      label: t('orderReturn.order_type'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true,
      slots: {
        default: ({ row }) => useEnumeratePicker(orderTypeList.value, row.order_type)
      }
    },
    {
      field: 'signatory',
      label: t('orderReturn.signatory'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true,
      slots: {
        default: ({ row }) => useEnumeratePicker(operatorList.value, row.signatory)
      }
    },
    {
      field: 'total_amount',
      label: t('orderReturn.total_amount'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'paid_amount',
      label: t('orderReturn.paid_amount'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'status',
      label: t('orderReturn.status'),
      minWidth: 200,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true,
      slots: {
        default: ({ row }) => useEnumeratePicker(statusList.value, row.status)
      }
    },
    {
      field: 'create_time',
      label: t('supply.create_time'),
      minWidth: 180,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'creator',
      label: t('supply.creator'),
      minWidth: 100,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true,
      slots: {
        default: ({ row }) => useEnumeratePicker(operatorList.value, row.creator)
      }
    },
    {
      field: 'update_time',
      label: t('supply.update_time'),
      minWidth: 180,
      align: 'center',
      headerAlign: 'center',
      showOverflowTooltip: true
    },
    {
      field: 'actions',
      label: '操作',
      fixed: 'right',
      width: 360,
      align: 'center',
      headerAlign: 'center',
      slots: {
        default: ({ row }) => (
          <>
            {row.status === 1 && (
              <ElButton size="small" onClick={() => handleJump('edit', row)}>
                {t('system.marketChannel.edit')}
              </ElButton>
            )}
            {row.status === 1 && hasPermission(['OrderReturnManageAudit']) && (
              <ElButton type="primary" size="small" onClick={() => examineHandle(row, 1)}>
                {t('purchase.examine_pass')}
              </ElButton>
            )}
            {row.status === 1 && (
              <ElButton type="primary" size="small" onClick={() => examineHandle(row, 2)}>
                {t('common.reject')}
              </ElButton>
            )}

            <ElButton type="success" size="small" onClick={() => handleJump('detail', row)}>
              {t('action.detail')}
            </ElButton>
            {row.status === 1 && userStore.getUserInfo?.id == row.creator && (
              <ElButton type="danger" size="small" onClick={() => handleCancel('single', row)}>
                {t('common.cancelExamine')}
              </ElButton>
            )}
          </>
        )
      }
    }
  ]
}
